package com.zeno.soil.rbac.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zeno.soil.rbac.model.vo.RoleItemVO;
import com.zeno.soil.rbac.model.bo.SubjectRoleBO;
import com.zeno.soil.rbac.repository.RoleMapper;
import com.zeno.soil.rbac.repository.SubjectRoleMapper;
import com.zeno.soil.rbac.repository.po.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zeno
 */
@Service
public class RoleService{

  private RoleMapper roleMapper;

  @Autowired
  private SubjectRoleMapper subjectRoleMapper;

  public List<RoleItemVO> findRoles(){

    LambdaQueryWrapper<Role> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.in(Role::getCode,"admin");
    queryWrapper.ne(Role::getName,"aaaa");
    List<Role> roles = roleMapper.selectList(queryWrapper);

    return RoleItemVO.createFrom(roles);
  }

  public List<SubjectRoleBO> findSubjectRoles(){

    List<SubjectRoleBO> subjectRoles = subjectRoleMapper.findSubjectRoles();

    return subjectRoles;
  }

  @Autowired
  public void setRoleMapper( RoleMapper roleMapper ){
    this.roleMapper = roleMapper;
  }
}
